﻿
@{
    ViewBag.Title = "Com";
}

<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form id="formSearch" class="form-horizontal">
                <div class="form-group" style="margin-top:15px">
                    <label class="control-label col-sm-1" for="txt_search_departmentname">职位名称</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="Name">
                    </div>
                    <label class="control-label col-sm-1" for="txt_search_statu">职位代码</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="Code">
                    </div>
                    <div class="col-sm-4" style="text-align:left;">
                        <button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary" onclick="Query()">查询</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div id="toolbar" class="btn-group">
        <button id="btn_add" type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
        </button>
        <button id="btn_edit" type="button" class="btn btn-default" onclick="GetUpdate()">
            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
        </button>
        <button id="btn_delete" type="button" class="btn btn-default" onclick="Del()">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
        </button>
        <button id="btn_delete" type="button" class="btn btn-default" onclick="downLoadExcle()">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>导出所有
        </button>
    </div>
    <table id="tb1"></table>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form class="form-inline" role="form" id="From1">
                <input type="hidden" id="Qing" />
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">添加职位详细信息</h4>
                </div>
                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">职位名称</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="txtName" placeholder="请输入职位名称">
                    </div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">职位代码</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="txtCode" placeholder="请输入职位代码">
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" onclick="Clear()">关闭</button>
                        <button type="button" class="btn btn-primary" onclick="Ok()">提交更改</button>
                    </div>
                </div>
</form>
</div>
</div>
@section  Scripts{
    <script src="~/Content/bootstraptable/dist/bootstrap-table.js"></script>
    <script src="~/Content/bootstraptable/dist/locale/bootstrap-table-zh-CN.min.js"></script>
    <link href="~/Content/bootstraptable/dist/bootstrap-table.css" rel="stylesheet" />
    <script>
        $(function () {
            Table();
        })

        function Query() {
            $('#tb1').bootstrapTable('refresh')
                    };
        function downLoadExcle() {
            window.location.href = '/Home/GetExcel';
        }


        function Del() {
            var a = $("#tb1").bootstrapTable('getSelections');
            if (a.length < 1) {
                alert("请选择数据");
                return;
            } else
                if (confirm("确定删除吗？")) {
                    var str = "";
                    for (var i = 0; i < a.length; i++) {
                        str += a[i].Id + ",";
                    }
                    str = str.substring(0, str.length - 1);
                    $.ajax({
                        url: "/Home/Del",
                        data: { id: str },
                        success: function (da) {
                            if (da == "OK") {
                                alert("操作成功");
                                Query();
                                Clear();
                                $("#myModal").modal('hide');
                            } else {
                                alert("失败");
                            }
                        }
                    });
                }
        }



        function GetUpdate() {
            var a = $("#tb1").bootstrapTable('getSelections');

            if (a.length > 1) {
                alert("只能选择一条数据修改");
                return;
            } else if (a.length < 1) {
                alert("请选择数据");
                return;
            } else if (a.length == 1) {
                $.ajax({
                    url: "/Home/GetUpda",
                    data: { id: a[0].Id },
                    success: function (da) {
                        $("#myModal").modal('show');
                        $("#txtName").val(da.Name);
                        $("#txtCode").val(da.Code);
                        $("#Qing").val(da.Id);
                    }
                });

            }

        }

        function Clear() {
            $("#txtName").val("");
            $("#txtCode").val("");
            $("#Qing").val("");
        }

        function Ok() {

            $.ajax({
                url: $("#Qing").val() == "" ? "/Home/Add" : "/Home/Upda",
                data: {
                    name: $("#txtName").val(),
                    code: $("#txtCode").val(),
                    id: $("#Qing").val()
                },
                success: function (da) {
                    if (da == "OK") {
                        alert("操作成功");
                        Query();
                        Clear();
                        $("#myModal").modal('hide');
                    } else {
                        alert("失败");
                    }
                }
            });
        }
        function Table() {
            $('#tb1').bootstrapTable({
                url: '/Home/ShowJobPageList',         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: true,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                /* queryParams: oTableInit.queryParams,*///传递参数（*）
                queryParams: function (params) {
                    params.name = $("#name").val();
                    params.code = $("code").val();
                    return params;
                },
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 3,                       //每页的记录行数（*）
                pageList: [3, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 1,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "Id",                     //每一行的唯一标识，一般为主键列
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [{
                    checkbox: true
                }, {
                    field: 'Name',
                    sortable:true,   //排序开启
                    title: '职位名称'
                }, {
                    field: 'Code',
                    sortable:true,   //排序开启
                    title: '职位代码'
                }]
            });
        };

    </script>
}


